package com.usian.service.impl;

import com.usian.pojo.TbItem;
import com.usian.redis.RedisClient;
import com.usian.service.CarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

@Service
@Transactional
public class CarServiceImpl implements CarService {


    @Value("${CART_REDIS_KEY}")
    private String CART_REDIS_KEY;

    @Autowired
    RedisClient redisClient;


    //将购物车信息添加到redis
    @Override
    public Boolean insertCart(String userId, Map cart) {
        return redisClient.hset(CART_REDIS_KEY,userId,cart);
    }

    //获取购物车信息
    @Override
    public Map<String, TbItem> selectCartByUserId(String userId) {
        return (Map<String, TbItem>) redisClient.hget(CART_REDIS_KEY, userId);
    }
}
